<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>优家购房系统 - 房屋信息更新</title>
	<script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<link rel="stylesheet" href="css/main.css">
	<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.css">
	
<script type="text/javascript">
	//根据传入的值默认选中option
	$(document).ready(function(){
		var isDoubleAir = ${house.h_isDoubleAir};
		//alert(isDoubleAir)
		var limit = '${house.h_limit}';
		var status = '${house.h_status}';
		$("#test option").each(function(){
			//alert($(this).val());
			if($(this).val()==isDoubleAir){
				$(this).attr("selected",true);
			}
		});
		$("#test2 option").each(function(){
			//alert($(this).val());
			if($(this).val()==limit){
				$(this).attr("selected",true);
			}
		});
		$("#test3 option").each(function(){
			//alert($(this).text());
			if($(this).val()==status){
				$(this).attr("selected",true);
			}
		});
		//ajax实现异步刷新
		$("#imgpath2").change(function(){
			var value = $("#imgpath2").val()
			//alert(666666)
			$.post("DataUpdate",{
				img : value
			},function(mes){
				//alert("Data Loaded:"+mes);
				$("#imgpath1").attr("src",mes);
			});
		});
		//将图片的地址赋值给隐藏域，然后由隐藏域把数据传入后台
		$(function(){
			//alert(6666)
			$("#imgpath2").change(function(){
				//alert(7777)
				$("#himg").val($("#imgpath2").val())
				//alert($("#himg").val($("#imgpath").val()))
			});
		});
	});
</script>

</head>
<body style="background:url('image/timg1.jpg');background-size:cover;">
<div class="box">
	<h3>更新房屋信息</h3>
	<form action="HouseServlet2?method=update" method="post">
		<input type="hidden" name="id" value="${house.h_id }">
		<table class="form-table">
			<tr>
				<td>地区</td>
				<td colspan="3" class="control">
					<input type="text" name="area" value="${house.h_area }">
				</td>
			</tr>
			<tr>
				<td>小区名字</td>
				<td colspan="3" class="control">
					<input type="text" name="estate" value="${house.h_estate }">
				</td>
			</tr>
			<tr>
				<td>单元号</td>
				<td colspan="3" class="control">
					<input type="text" name="unitNumber" value="${house.h_unitNumber }">
				</td>
			</tr>
			<tr>
				<td>楼层</td>
				<td colspan="3" class="control">
					<input type="text" name="floor" value="${house.h_floor }">
				</td>
			</tr>
			<tr>
				<td>房间号</td>
				<td colspan="3" class="control">
					<input type="text" name="roomNo" value="${house.h_roomNo }">
				</td>
			</tr>
			<tr>
				<td>面积（平米）</td>
				<td colspan="3" class="control">
					<input type="text" name="acreage" value="${house.h_acreage }">
				</td>
			</tr>
			<tr>
				<td>朝向</td>
				<td colspan="3" class="control">
					<input type="text" name="direction" value="${house.h_direction }">
				</td>
			</tr>
			<tr>
				<td>装修</td>
				<td colspan="3" class="control">
					<input type="text" name="fitment" value="${house.h_fitment }">
				</td>
			</tr>
			<tr>
				<td>是否双气</td>
				<td colspan="3" class="control">
					<select name="isDoubleAir" id="test">
						<option value="0">天然气</option>
						<option value="1">暖气</option>
						<option value="2">双气</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>限住人数</td>
				<td colspan="3" class="control" id="test2">
					<select name="limit" id="test2">
					<option value="1">单人间</option>
					<option value="2">双人间</option>
					<option value="3">三人间</option>
					<option value="4">四人间</option>
					<option value="5">五人间</option>
					<option value="6">六人间</option>
				</select>
				</td>
			</tr>
			<tr>
				<td>配套设施</td>
				<td colspan="3" class="control">
					<input type="text" name="facility" value="${house.h_facility }">
				</td>
			</tr>
			<tr>
				<td>出租价格（元/月）</td>
				<td colspan="3" class="control">
					<input type="text" name="price" value="${house.h_price }">
				</td>
			</tr>
			<tr>
				<td>出租状态</td>
				<td colspan="3" class="control">
					<select name="status" id="test3">
						<option value="2">未出租</option>
						<option value="1">已出租</option>
						<option value="0">停止出租</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>房屋图片</td>
				<td colspan="3" class="control">
				<input type="hidden" id="himg" name="img">
					<p><img src="image/${house.h_img }" width="300px" height="200px" id="imgpath1"></p>
					<input type="file" id="imgpath2">
				</td>
			</tr>
			<tr>
				<td>完整地址信息</td>
				<td colspan="3" class="control">
					<input type="text" name="address" value="${house.h_address }">
				</td>
			</tr>

			<tr>
			<td>添加时间</td>
			<td colspan="3" class="control">
				<input type="text" name="addTime" value="${house.h_addtime }" readonly>
			</td>
		</tr>
		<tr>
			<td>更新时间</td>
			<td colspan="3" class="control">
				<input type="text" name="updateTime" value="${house.h_updateTime }" class="Wdate" onClick="WdatePicker()">
			</td>
		</tr>
		</table>
		<div class="buttons">
			<input class="btn btn-primary va-bottom" type="submit" value="保存">&nbsp;&nbsp;
			<a class="btn btn-default" href="javascript:history.go(-1)">返回</a>
		</div>
	</form>
</div>
</body>
</html>